package klimuts.periodicals.user;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import klimuts.periodicals.admin.actions.ShowUser;
import klimuts.periodicals.admin.actions.ShowUsers;
import klimuts.periodicals.user.actions.Login;

/**
 * Class contains all information about user.
 * @author Siarhei Klimuts
 */
@Entity
@Table(name="users")
public class User {
	private long id;
	private byte rights;
	private String firstName;
    private String lastName;
    private String email;	
	private String login;
	private String password;
	private String address;
	
	public User() {}
	
	/**
	 * Constructor for new user registration
	 * @param {@link Byte} rights 
	 * @param {@link String} firstName 
	 * @param {@link String} lastName 
	 * @param {@link String} email 
	 * @param {@link String} login 
	 * @param {@link String} password 
	 * @param {@link String} address 
	 */
	public User(byte rights, String firstName, String lastName, String email, String login, String password, String address) {
		setRights(rights);
		setFirstName(firstName);
		setLastName(lastName);
		setEmail(email);
		setLogin(login);
		setPassword(password);
		setAddress(address);
	}
	
	/**
	 * Short constructor for {@link ShowUsers} action
	 * @param {@link Long} id - for {@link ShowUser} action
	 * @param {@link String} login - for display
	 */
	public User(long id, String login) {
		setId(id);
		setLogin(login);
	}
	
	/**
	 * Short user-side constructor for {@link Login} action
	 * @param {@link Long} id - for order placing  
	 * @param {@link Byte} rights - for administrator page access
	 */
	public User(long id, byte rights) {
		setId(id);
		setRights(rights);
	}
	
	public String toString() {
		return login;
	}
	
	/**
	 * Used when need text output of rights value
	 * @return Return {@link String} key in *.properties file for current rights value. 
	 */ 
	@Transient
	public String getRightsText() {
		return "user.rights."+rights;
	}

	@Id
	@GeneratedValue
	public long getId(){
		return id;
	}
	
	protected void setId(long id){
		this.id=id;
	}
	
	public byte getRights(){
		return rights;
	}
	
	public void setRights(byte rights){
		this.rights=rights;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLogin(){
		return login;
	}
	
	public void setLogin(String login){
		this.login=login;
	}
	
	protected String getPassword() {
		return password;
	}

	protected void setPassword(String password) {
		this.password = password;
	}

	public String getAddress(){
		return address;
	}
	
	public void setAddress(String address){
		this.address=address;
	}	
	
}
